package com.multidisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.multidisplay.bo.InfoBo;
import com.multidisplay.bo.ResultBo;
import com.multidisplay.mapper.EquipMapper;
import com.multidisplay.mapper.WebPageMapper;
import com.multidisplay.po.Equipment;
import com.multidisplay.po.WebPage;
import com.multidisplay.service.EquipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EquipServiceImpl implements EquipService {
    @Autowired
    private EquipMapper equipMapper;
    @Autowired
    private WebPageMapper webPageMapper;

    @Override
    public ResultBo<Equipment> queryEquip(int page, int limit){
        IPage iPage = new Page(page, limit);
        IPage<Equipment> equipmentIPage = equipMapper.selectPage(iPage,null);
        ResultBo<Equipment> resultBo = new ResultBo<>();
        resultBo.setCode(0);
        resultBo.setMsg("");
        resultBo.setCount(equipmentIPage.getTotal());
        resultBo.setData(equipmentIPage.getRecords());
        return resultBo;
    }   //分页查询所有终端

    @Override
    public void updateEquip(Equipment equipment){
        equipMapper.updateById(equipment);
    }   //修改终端基本信息

    @Override
    public void deleteEquip(Equipment equipment){
        QueryWrapper<Equipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("eq_id",equipment.getId());
        equipMapper.delete(queryWrapper);
    }   //根据ID删除终端

    @Override
    public void addEquip(Equipment equipment){
        equipMapper.insert(equipment);
    }   //新增终端

    @Override
    public void pageId(Equipment equipment){
        equipMapper.updateById(equipment);
    }   //终端关联页面

    @Override
    public InfoBo<String> showPageInfo(String flag){
        QueryWrapper<WebPage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("flag",flag);
        WebPage webPage = webPageMapper.selectOne(queryWrapper);
        InfoBo<String> infoBo = new InfoBo<>();
        infoBo.setCode(0);
        infoBo.setMsg("根据终端标识符"+flag+"查得的页面信息");
        infoBo.setData(webPage.toStringList());
        return infoBo;
    }  //根据终端标识符查询对应的页面信息
}
